package com.lmf.filter;


import com.netflix.zuul.context.RequestContext;
import org.springframework.cloud.netflix.zuul.filters.post.SendErrorFilter;
import org.springframework.stereotype.Component;
import org.springframework.util.ReflectionUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@Component
public class ErrortFilter extends SendErrorFilter {
    public Object run() {
        String msg="request error";
        RequestContext ctx=RequestContext.getCurrentContext();
        ExceptionHolder exceptionHolder=findZuulException(ctx.getThrowable());
        System.out.println("error"+exceptionHolder.getErrorCause());
        msg+="error :"+exceptionHolder.getErrorCause();
        HttpServletResponse response=ctx.getResponse();
       // response.setCharacterEncoding("UTF-8");
        try {
            response.getOutputStream().write(msg.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
            ReflectionUtils.rethrowRuntimeException(e);
        }
        return null;
    }
}
